import { Search, ITEM_TYPE } from './js/search';

window.addEventListener('load', function () {
    var items = [];
    for (var i = 6; i < 50; i++) {
        items.push({ label: '南京总统府，奠基仪式' + i, value: i });
    }

    var s = new Search('[fn-search]', {
        // 自动完成分词词典
        dict: ['总统府', '知名作家'],
        // 自动完成数据源配置
        source: [
            {
                key: 'project',
                data: [
                    {
                        label: '中文在线以自有原创平台、知名作家、版权机构为正版数字内容来源',
                        value: 1,
                    },
                    { label: '中文在线已构成一主多元的原创内容生产平台', value: 2 },
                    { label: '不但布局17K主平台', value: 3 },
                    { label: '同时布局多种垂类赛道', value: 4 },
                    { label: '包括四月天、奇想宇宙和谜想计划等', value: 5 },
                    ...items,
                ],
            },
        ],
        items: [
            {
                label: '项目',
                inputName: 'project',
                type: ITEM_TYPE.AUTO_COMPLETE,
                defaultValue: 3,
            },
            {
                label: '分类',
                inputName: 'categoryId',
                type: ITEM_TYPE.SELECT,
                data: [
                    { label: '第一个', value: 'a' },
                    { label: '第二个', value: 'b' },
                ],
                defaultValue: 'a',
            },
            {
                label: '级联分类',
                inputName: 'categories',
                type: ITEM_TYPE.DROPDOWN,
                data: [
                    {
                        label: '什么A',
                        value: 'a',
                        children: [
                            {
                                label: 'A-1',
                                value: 'a1',
                                children: [
                                    { label: 'A-1-1', value: 'a11' },
                                    { label: 'A-1-2', value: 'a12' },
                                ],
                            },
                            {
                                label: 'A-2',
                                value: 'a2',
                                children: [
                                    { label: 'A-2-1', value: 'a21' },
                                    { label: 'A-2-2', value: 'a22' },
                                ],
                            },
                        ],
                    },
                    { label: 'B', value: 'b', children: [{ label: 'B-1', value: 'b1' }] },
                ],
                defaultValue: 'a21',
            },
            {
                label: '日期',
                inputName: 'date',
                type: ITEM_TYPE.DATE_PICKER,
                defaultValue: '2024-01-05',
            },
            {
                label: '日期段',
                inputName: 'date-range',
                type: ITEM_TYPE.DATE_RANGE_PICKER,
                defaultValue: ['2024-01-05', '2024-01-26'],
            },
            { label: '电子邮箱', inputName: 'email', type: ITEM_TYPE.TEXT, defaultValue: '6298398@qq.com' },
        ],
    });

    // 主动发起搜索
    setTimeout(() => {
        s.search({
            project: 1,
            categoryId: 'b',
            categories: 'a12',
            date: '2024-03-05',
            'date-range': ['2024-03-05', '2024-03-26'],
            email: '62aaaa98@qq.com',
        })
    }, 5000);
});
